package embeddable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import embeddable.EmbeddedPKBook;

public class EmbeddableTest {
	SessionFactory sessionFactory;
	
	@BeforeClass
	public void setup(){
		Configuration cfg = new Configuration();
		cfg.configure();
		StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
		serviceRegistryBuilder.applySettings(cfg.getProperties());
		sessionFactory = cfg.buildSessionFactory(serviceRegistryBuilder.build());		
	}
	@Test
	public void testEmbeddedIdKey(){
		EmbeddedPKBook pkBook = new EmbeddedPKBook();
		EmbeddedPKBook.EmbeddedISBN isbn = new EmbeddedPKBook.EmbeddedISBN();
		isbn.checkdigit=111;
		isbn.group = 222;
		isbn.publisher = 333;
		isbn.title = 444;
		pkBook.name="Embedded Book";
		pkBook.id = isbn;
		
		Session session = sessionFactory.openSession();
		Transaction txn = session.beginTransaction();
		session.save(pkBook);
		txn.commit();
		session.close();
	}

	public EmbeddableTest() {
		// TODO Auto-generated constructor stub
	}

}
